var config = require('../../config.js')
var http = require('../..//utils/httpHelper.js')
var app = getApp()
Page({
  data: {
    userInfo:{},
    allAddress: [],//地址列表
  },
  onLoad: function () {
    var that = this;
    let userInfo = wx.getStorageSync('user');
    that.setData({userInfo:userInfo});
  },
  onShow:function(){
    this.getAllAddressList();
  },
  getAllAddressList:function(){
    var that = this;
    var data = {userId:this.data.userInfo.userId};
    http.httpGet(config.clubApi.getAddressList,data,function(res){
      if(res.code == '200'){
        that.setData({allAddress:res.data});
      }
    });
  },
  radioChange:function(e){
    var id = e.detail.value;
    var data = {userId:this.data.userInfo.userId,id:id,isfirst:1}
    http.httpPut(config.clubApi.editAddress,data,function(res){
      if(res.code == '200'){
        console.log("设置默认地址成功");
      }else{
        console.log("设置默认地址失败");
      }
    });
  },
  addrss:function (e){
    wx.navigateTo({url:"/pages/address/addto/index?id="})
  },
  addto:function (e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({url:"/pages/address/addto/index?id="+id})
  }
})